home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb.new / gdb-3.98 / gdb / symm-xdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-01  |  14.8 KB  |  558 lines

  1. /* Sequent Symmetry host interface, for GDB when running under Unix.
  2.    Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* many 387-specific items of use taken from i386-dep.c */
  21.  
  22. #include <stdio.h>
  23. #include "defs.h"
  24. #include "param.h"
  25. #include "frame.h"
  26. #include "inferior.h"
  27. #include "symtab.h"
  28.  
  29. #include <signal.h>
  30. #include <sys/param.h>
  31. #include <sys/user.h>
  32. #include <sys/dir.h>
  33. #include <sys/ioctl.h>
  34. #include <sys/stat.h>
  35. #include "gdbcore.h"
  36. #include <fcntl.h>
  37.  
  38. static long i386_get_frame_setup ();
  39. static i386_follow_jump ();
  40.  
  41. #include <sgtty.h>
  42. #define TERMINAL struct sgttyb
  43.  
  44. store_inferior_registers(regno)
  45. int regno;
  46. {
  47.   struct pt_regset regs;
  48.   int reg_tmp, i;
  49.   extern char registers[];
  50.   
  51. #if 0
  52.   /* PREPARE_TO_STORE deals with this.  */
  53.   if (-1 == regno)
  54.     {
  55. #endif
  56.       regs.pr_eax = *(int *)®isters[REGISTER_BYTE(0)];
  57.       regs.pr_ebx = *(int *)®isters[REGISTER_BYTE(5)];
  58.       regs.pr_ecx = *(int *)®isters[REGISTER_BYTE(2)];
  59.       regs.pr_edx = *(int *)®isters[REGISTER_BYTE(1)];
  60.       regs.pr_esi = *(int *)®isters[REGISTER_BYTE(6)];
  61.       regs.pr_edi = *(int *)®isters[REGISTER_BYTE(7)];
  62.       regs.pr_esp = *(int *)®isters[REGISTER_BYTE(14)];
  63.       regs.pr_ebp = *(int *)®isters[REGISTER_BYTE(15)];
  64.       regs.pr_eip = *(int *)®isters[REGISTER_BYTE(16)];
  65.       regs.pr_flags = *(int *)®isters[REGISTER_BYTE(17)];
  66.       for (i = 0; i < 31; i++) {
  67.     regs.pr_fpa.fpa_regs[i] =
  68.       *(int *)®isters[REGISTER_BYTE(FP1_REGNUM+i)];
  69.       }
  70. #if 0
  71.     }
  72.   else
  73.     {
  74.       reg_tmp = *(int *)®isters[REGISTER_BYTE(regno)];
  75.       ptrace(XPT_RREGS, inferior_pid, ®s, 0);
  76.       switch (regno)
  77.     {
  78.     case 0:
  79.       regs.pr_eax = *(int *)®isters[REGISTER_BYTE(0)];
  80.       break;
  81.     case 5:
  82.       regs.pr_ebx = *(int *)®isters[REGISTER_BYTE(5)];
  83.       break;
  84.     case 2:
  85.       regs.pr_ecx = *(int *)®isters[REGISTER_BYTE(2)];
  86.       break;
  87.     case 1:
  88.       regs.pr_edx = *(int *)®isters[REGISTER_BYTE(1)];
  89.       break;
  90.     case 6:
  91.       regs.pr_esi = *(int *)®isters[REGISTER_BYTE(6)];
  92.       break;
  93.     case 7:
  94.       regs.pr_edi = *(int *)®isters[REGISTER_BYTE(7)];
  95.       break;
  96.     case 15:
  97.       regs.pr_ebp = *(int *)®isters[REGISTER_BYTE(15)];
  98.       break;
  99.     case 14:
  100.       regs.pr_esp = *(int *)®isters[REGISTER_BYTE(14)];
  101.       break;
  102.     case 16:
  103.       regs.pr_eip = *(int *)®isters[REGISTER_BYTE(16)];
  104.       break;
  105.     case 17:
  106.       regs.pr_flags = *(int *)®isters[REGISTER_BYTE(17)];
  107.       break;
  108.     }
  109.     }
  110. #endif /* 0 */
  111.   ptrace(XPT_WREGS, inferior_pid, ®s, 0);
  112. }
  113.  
  114. void
  115. fetch_inferior_registers()
  116. {
  117.     int i;
  118.     struct pt_regset regs;
  119.     extern char registers[];
  120.  
  121.     registers_fetched ();
  122.     
  123.     ptrace(XPT_RREGS, inferior_pid, ®s, 0);
  124.     *(int *)®isters[REGISTER_BYTE(0)] = regs.pr_eax;
  125.     *(int *)®isters[REGISTER_BYTE(5)] = regs.pr_ebx;
  126.     *(int *)®isters[REGISTER_BYTE(2)] = regs.pr_ecx;
  127.     *(int *)®isters[REGISTER_BYTE(1)] = regs.pr_edx;
  128.     *(int *)®isters[REGISTER_BYTE(6)] = regs.pr_esi;
  129.     *(int *)®isters[REGISTER_BYTE(7)] = regs.pr_edi;
  130.     *(int *)®isters[REGISTER_BYTE(15)] = regs.pr_ebp;
  131.     *(int *)®isters[REGISTER_BYTE(14)] = regs.pr_esp;
  132.     *(int *)®isters[REGISTER_BYTE(16)] = regs.pr_eip;
  133.     *(int *)®isters[REGISTER_BYTE(17)] = regs.pr_flags;
  134.     for (i = 0; i < FPA_NREGS; i++) {
  135.     *(int *)®isters[REGISTER_BYTE(FP1_REGNUM+i)] = regs.pr_fpa.fpa_regs[i];
  136.     }
  137.     bcopy(regs.pr_fpu.fpu_stack[0], ®isters[REGISTER_BYTE(3)], 10);
  138.     bcopy(regs.pr_fpu.fpu_stack[1], ®isters[REGISTER_BYTE(4)], 10);
  139.     bcopy(regs.pr_fpu.fpu_stack[2], ®isters[REGISTER_BYTE(8)], 10);
  140.     bcopy(regs.pr_fpu.fpu_stack[3], ®isters[REGISTER_BYTE(9)], 10);
  141.     bcopy(regs.pr_fpu.fpu_stack[4], ®isters[REGISTER_BYTE(10)], 10);
  142.     bcopy(regs.pr_fpu.fpu_stack[5], ®isters[REGISTER_BYTE(11)], 10);
  143.     bcopy(regs.pr_fpu.fpu_stack[6], ®isters[REGISTER_BYTE(12)], 10);
  144.     bcopy(regs.pr_fpu.fpu_stack[7], ®isters[REGISTER_BYTE(13)], 10);
  145. }
  146.  
  147.  
  148. /* Work with core dump and executable files, for GDB. 
  149.    This code would be in core.c if it weren't machine-dependent. */
  150.  
  151. #include "gdbcore.h"
  152.  
  153. void
  154. core_file_command (filename, from_tty)
  155.      char *filename;
  156.      int from_tty;
  157. {
  158.   int val;
  159.   extern char registers[];
  160.  
  161.   /* Discard all vestiges of any previous core file
  162.      and mark data and stack spaces as empty.  */
  163.  
  164.   if (corefile)
  165.     free (corefile);
  166.   corefile = 0;
  167.  
  168.   if (corechan >= 0)
  169.     close (corechan);
  170.   corechan = -1;
  171.  
  172.   data_start = 0;
  173.   data_end = 0;
  174.   stack_start = STACK_END_ADDR;
  175.   stack_end = STACK_END_ADDR;
  176.  
  177.   /* Now, if a new core file was specified, open it and digest it.  */
  178.  
  179.   if (filename)
  180.     {
  181.       filename = tilde_expand (filename);
  182.       make_cleanup (free, filename);
  183.       
  184.       if (have_inferior_p ())
  185.     error ("To look at a core file, you must kill the inferior with \"kill\".");
  186.       corechan = open (filename, O_RDONLY, 0);
  187.       if (corechan < 0)
  188.     perror_with_name (filename);
  189.       /* 4.2-style (and perhaps also sysV-style) core dump file.  */
  190.       {
  191.     struct user u;
  192.     int reg_offset;
  193.  
  194.     val = myread (corechan, &u, sizeof u);
  195.     if (val < 0)
  196.       perror_with_name (filename);
  197.     data_start = exec_data_start;
  198.  
  199.     data_end = data_start + NBPG * (u.u_dsize - u.u_tsize);
  200.     stack_start = stack_end - NBPG * u.u_ssize;
  201.     data_offset = NBPG * UPAGES;
  202.     stack_offset = ctob(UPAGES + u.u_dsize - u.u_tsize);
  203.     reg_offset = (int) u.u_ar0 - KERNEL_U_ADDR;
  204. printf("u.u_tsize= %#x, u.u_dsize= %#x, u.u_ssize= %#x, stack_off= %#x\n",
  205.        u.u_tsize, u.u_dsize, u.u_ssize, stack_offset);
  206.  
  207.     core_aouthdr.a_magic = 0;
  208.  
  209.     /* Read the register values out of the core file and store
  210.        them where `read_register' will find them.  */
  211.  
  212.     {
  213.       register int regno;
  214.  
  215.       for (regno = 0; regno < NUM_REGS; regno++)
  216.         {
  217.           char buf[MAX_REGISTER_RAW_SIZE];
  218.  
  219.           val = lseek (corechan, register_addr (regno, reg_offset), 0);
  220.           if (val < 0)
  221.         perror_with_name (filename);
  222.  
  223.            val = myread (corechan, buf, sizeof buf);
  224.           if (val < 0)
  225.         perror_with_name (filename);
  226.           supply_register (regno, buf);
  227.         }
  228.     }
  229.       }
  230.       if (filename[0] == '/')
  231.     corefile = savestring (filename, strlen (filename));
  232.       else
  233.     {
  234.       corefile = concat (current_directory, "/", filename);
  235.     }
  236.  
  237.       set_current_frame(create_new_frame(read_register(FP_REGNUM),
  238.                      read_pc()));
  239. /*      set_current_frame (read_register (FP_REGNUM));*/
  240.       select_frame (get_current_frame (), 0);
  241.       validate_files ();
  242.     }
  243.   else if (from_tty)
  244.     printf ("No core file now.\n");
  245. }
  246.  
  247. /* from i386-dep.c */
  248. static
  249. print_387_control_word (control)
  250. unsigned short control;
  251. {
  252.   printf ("control 0x%04x: ", control);
  253.   printf ("compute to ");
  254.   switch ((control >> 8) & 3) 
  255.     {
  256.     case 0: printf ("24 bits; "); break;
  257.     case 1: printf ("(bad); "); break;
  258.     case 2: printf ("53 bits; "); break;
  259.     case 3: printf ("64 bits; "); break;
  260.     }
  261.   printf ("round ");
  262.   switch ((control >> 10) & 3) 
  263.     {
  264.     case 0: printf ("NEAREST; "); break;
  265.     case 1: printf ("DOWN; "); break;
  266.     case 2: printf ("UP; "); break;
  267.     case 3: printf ("CHOP; "); break;
  268.     }
  269.   if (control & 0x3f) 
  270.     {
  271.       printf ("mask:");
  272.       if (control & 0x0001) printf (" INVALID");
  273.       if (control & 0x0002) printf (" DENORM");
  274.       if (control & 0x0004) printf (" DIVZ");
  275.       if (control & 0x0008) printf (" OVERF");
  276.       if (control & 0x0010) printf (" UNDERF");
  277.       if (control & 0x0020) printf (" LOS");
  278.       printf (";");
  279.     }
  280.   printf ("\n");
  281.   if (control & 0xe080) printf ("warning: reserved bits on 0x%x\n",
  282.                 control & 0xe080);
  283. }
  284.  
  285. static
  286. print_387_status_word (status)
  287.      unsigned short status;
  288. {
  289.   printf ("status %#04x: ", status);
  290.   if (status & 0xff) {
  291.       printf ("exceptions:");    /* exception names match <machine/fpu.h> */
  292.       if (status & 0x0001) printf (" FLTINV");
  293.       if (status & 0x0002) printf (" FLTDEN");
  294.       if (status & 0x0004) printf (" FLTDIV");
  295.       if (status & 0x0008) printf (" FLTOVF");
  296.       if (status & 0x0010) printf (" FLTUND");
  297.       if (status & 0x0020) printf (" FLTPRE");
  298.       if (status & 0x0040) printf (" FLTSTK");
  299.       printf ("; ");
  300.     }
  301.   printf ("flags: %d%d%d%d; ",
  302.       (status & 0x4000) != 0,
  303.       (status & 0x0400) != 0,
  304.       (status & 0x0200) != 0,
  305.       (status & 0x0100) != 0);
  306.   
  307.   printf ("top %d\n", (status >> 11) & 7);
  308. }
  309.  
  310. static
  311. print_fpu_status(ep)
  312. struct pt_regset ep;
  313.  
  314. {
  315.     int i;
  316.     int bothstatus;
  317.     int top;
  318.     int fpreg;
  319.     unsigned char *p;
  320.     
  321.     printf("80387:");
  322.     if (ep.pr_fpu.fpu_ip == 0) {
  323.     printf(" not in use.\n");
  324.     return;
  325.     } else {
  326.     printf("\n");
  327.     }
  328.     if (ep.pr_fpu.fpu_status != 0) {
  329.     print_387_status_word (ep.pr_fpu.fpu_status);
  330.     }
  331.     print_387_control_word (ep.pr_fpu.fpu_control);
  332.     printf ("last exception: ");
  333.     printf ("opcode 0x%x; ", ep.pr_fpu.fpu_rsvd4);
  334.     printf ("pc 0x%x:0x%x; ", ep.pr_fpu.fpu_cs, ep.pr_fpu.fpu_ip);
  335.     printf ("operand 0x%x:0x%x\n", ep.pr_fpu.fpu_data_offset, ep.pr_fpu.fpu_op_sel);
  336.     
  337.     top = (ep.pr_fpu.fpu_status >> 11) & 7;
  338.     
  339.     printf ("regno  tag  msb              lsb  value\n");
  340.     for (fpreg = 7; fpreg >= 0; fpreg--) 
  341.     {
  342.         double val;
  343.         
  344.         printf ("%s %d: ", fpreg == top ? "=>" : "  ", fpreg);
  345.         
  346.         switch ((ep.pr_fpu.fpu_tag >> (fpreg * 2)) & 3) 
  347.         {
  348.         case 0: printf ("valid "); break;
  349.         case 1: printf ("zero  "); break;
  350.         case 2: printf ("trap  "); break;
  351.         case 3: printf ("empty "); break;
  352.         }
  353.         for (i = 9; i >= 0; i--)
  354.         printf ("%02x", ep.pr_fpu.fpu_stack[fpreg][i]);
  355.         
  356.         i387_to_double (ep.pr_fpu.fpu_stack[fpreg], (char *)&val);
  357.         printf ("  %g\n", val);
  358.     }
  359.     if (ep.pr_fpu.fpu_rsvd1)
  360.     printf ("warning: rsvd1 is 0x%x\n", ep.pr_fpu.fpu_rsvd1);
  361.     if (ep.pr_fpu.fpu_rsvd2)
  362.     printf ("warning: rsvd2 is 0x%x\n", ep.pr_fpu.fpu_rsvd2);
  363.     if (ep.pr_fpu.fpu_rsvd3)
  364.     printf ("warning: rsvd3 is 0x%x\n", ep.pr_fpu.fpu_rsvd3);
  365.     if (ep.pr_fpu.fpu_rsvd5)
  366.     printf ("warning: rsvd5 is 0x%x\n", ep.pr_fpu.fpu_rsvd5);
  367. }
  368.  
  369.  
  370. print_1167_control_word(pcr)
  371. unsigned int pcr;
  372.  
  373. {
  374.     int pcr_tmp;
  375.  
  376.     pcr_tmp = pcr & FPA_PCR_MODE;
  377.     printf("\tMODE= %#x; RND= %#x ", pcr_tmp, pcr_tmp & 12);
  378.     switch (pcr_tmp & 12) {
  379.     case 0:
  380.     printf("RN (Nearest Value)");
  381.     break;
  382.     case 1:
  383.     printf("RZ (Zero)");
  384.     break;
  385.     case 2:
  386.     printf("RP (Positive Infinity)");
  387.     break;
  388.     case 3:
  389.     printf("RM (Negative Infinity)");
  390.     break;
  391.     }
  392.     printf("; IRND= %d ", pcr_tmp & 2);
  393.     if (0 == pcr_tmp & 2) {
  394.     printf("(same as RND)\n");
  395.     } else {
  396.     printf("(toward zero)\n");
  397.     }
  398.     pcr_tmp = pcr & FPA_PCR_EM;
  399.     printf("\tEM= %#x", pcr_tmp);
  400.     if (pcr_tmp & FPA_PCR_EM_DM) printf(" DM");
  401.     if (pcr_tmp & FPA_PCR_EM_UOM) printf(" UOM");
  402.     if (pcr_tmp & FPA_PCR_EM_PM) printf(" PM");
  403.     if (pcr_tmp & FPA_PCR_EM_UM) printf(" UM");
  404.     if (pcr_tmp & FPA_PCR_EM_OM) printf(" OM");
  405.     if (pcr_tmp & FPA_PCR_EM_ZM) printf(" ZM");
  406.     if (pcr_tmp & FPA_PCR_EM_IM) printf(" IM");
  407.     printf("\n");
  408.     pcr_tmp = FPA_PCR_CC;
  409.     printf("\tCC= %#x", pcr_tmp);
  410.     if (pcr_tmp & FPA_PCR_20MHZ) printf(" 20MHZ");
  411.     if (pcr_tmp & FPA_PCR_CC_Z) printf(" Z");
  412.     if (pcr_tmp & FPA_PCR_CC_C2) printf(" C2");
  413.     if (pcr_tmp & FPA_PCR_CC_C1) printf(" C1");
  414.     switch (pcr_tmp) {
  415.     case FPA_PCR_CC_Z:
  416.     printf(" (Equal)");
  417.     break;
  418.     case FPA_PCR_CC_C1:
  419.     printf(" (Less than)");
  420.     break;
  421.     case 0:
  422.     printf(" (Greater than)");
  423.     break;
  424.     case FPA_PCR_CC_Z | FPA_PCR_CC_C1 | FPA_PCR_CC_C2:
  425.     printf(" (Unordered)");
  426.     break;
  427.     default:
  428.     printf(" (Undefined)");
  429.     break;
  430.     }
  431.     printf("\n");
  432.     pcr_tmp = pcr & FPA_PCR_AE;
  433.     printf("\tAE= %#x", pcr_tmp);
  434.     if (pcr_tmp & FPA_PCR_AE_DE) printf(" DE");
  435.     if (pcr_tmp & FPA_PCR_AE_UOE) printf(" UOE");
  436.     if (pcr_tmp & FPA_PCR_AE_PE) printf(" PE");
  437.     if (pcr_tmp & FPA_PCR_AE_UE) printf(" UE");
  438.     if (pcr_tmp & FPA_PCR_AE_OE) printf(" OE");
  439.     if (pcr_tmp & FPA_PCR_AE_ZE) printf(" ZE");
  440.     if (pcr_tmp & FPA_PCR_AE_EE) printf(" EE");
  441.     if (pcr_tmp & FPA_PCR_AE_IE) printf(" IE");
  442.     printf("\n");
  443. }
  444.  
  445. print_1167_regs(regs)
  446. long regs[FPA_NREGS];
  447.  
  448. {
  449.     int i;
  450.  
  451.     union {
  452.     double    d;
  453.     long    l[2];
  454.     } xd;
  455.     union {
  456.     float    f;
  457.     long    l;
  458.     } xf;
  459.  
  460.  
  461.     for (i = 0; i < FPA_NREGS; i++) {
  462.     xf.l = regs[i];
  463.     printf("%%fp%d: raw= %#x, single= %f", i+1, regs[i], xf.f);
  464.     if (!(i & 1)) {
  465.         printf("\n");
  466.     } else {
  467.         xd.l[1] = regs[i];
  468.         xd.l[0] = regs[i+1];
  469.         printf(", double= %f\n", xd.d);
  470.     }
  471.     }
  472. }
  473.  
  474. print_fpa_status(ep)
  475. struct pt_regset ep;
  476.  
  477. {
  478.  
  479.     printf("WTL 1167:");
  480.     if (ep.pr_fpa.fpa_pcr !=0) {
  481.     printf("\n");
  482.     print_1167_control_word(ep.pr_fpa.fpa_pcr);
  483.     print_1167_regs(ep.pr_fpa.fpa_regs);
  484.     } else {
  485.     printf(" not in use.\n");
  486.     }
  487. }
  488.  
  489. i386_float_info ()
  490.  
  491. {
  492.     char ubuf[UPAGES*NBPG];
  493.     struct pt_regset regset;
  494.     extern int corechan;
  495.     
  496.     if (have_inferior_p()) {
  497.     call_ptrace(XPT_RREGS, inferior_pid, ®set, 0);
  498.     } else {
  499.     if (lseek (corechan, 0, 0) < 0) {
  500.         perror ("seek on core file");
  501.     }
  502.     if (myread (corechan, ubuf, UPAGES*NBPG) < 0) {
  503.         perror ("read on core file");
  504.     }
  505.     /* only interested in the floating point registers */
  506.     regset.pr_fpu = ((struct user *) ubuf)->u_fpusave;
  507.     regset.pr_fpa = ((struct user *) ubuf)->u_fpasave;
  508.     }
  509.     print_fpu_status(regset);
  510.     print_fpa_status(regset);
  511. }
  512.  
  513. i387_to_double (from, to)
  514.      char *from;
  515.      char *to;
  516. {
  517.   long *lp;
  518.   /* push extended mode on 387 stack, then pop in double mode
  519.    *
  520.    * first, set exception masks so no error is generated -
  521.    * number will be rounded to inf or 0, if necessary 
  522.    */
  523.   asm ("pushl %eax");         /* grab a stack slot */
  524.   asm ("fstcw (%esp)");        /* get 387 control word */
  525.   asm ("movl (%esp),%eax");    /* save old value */
  526.   asm ("orl $0x3f,%eax");        /* mask all exceptions */
  527.   asm ("pushl %eax");
  528.   asm ("fldcw (%esp)");        /* load new value into 387 */
  529.   
  530.   asm ("movl 8(%ebp),%eax");
  531.   asm ("fldt (%eax)");        /* push extended number on 387 stack */
  532.   asm ("fwait");
  533.   asm ("movl 12(%ebp),%eax");
  534.   asm ("fstpl (%eax)");        /* pop double */
  535.   asm ("fwait");
  536.   
  537.   asm ("popl %eax");        /* flush modified control word */
  538.   asm ("fnclex");            /* clear exceptions */
  539.   asm ("fldcw (%esp)");        /* restore original control word */
  540.   asm ("popl %eax");        /* flush saved copy */
  541. }
  542.  
  543. double_to_i387 (from, to)
  544.      char *from;
  545.      char *to;
  546. {
  547.   /* push double mode on 387 stack, then pop in extended mode
  548.    * no errors are possible because every 64-bit pattern
  549.    * can be converted to an extended
  550.    */
  551.   asm ("movl 8(%ebp),%eax");
  552.   asm ("fldl (%eax)");
  553.   asm ("fwait");
  554.   asm ("movl 12(%ebp),%eax");
  555.   asm ("fstpt (%eax)");
  556.   asm ("fwait");
  557. }
  558.